<?php

namespace App\Http\Controllers\Customer;

use App\Http\Controllers\Controller;
use App\Models\AddressModel;
use App\Models\client\MsgModel;
use App\Models\CountryModel;
use Illuminate\Http\Request;

class Msg extends Controller
{

    public function index(Request $request){
        $auth = $request->get('auth');

        $msg = MsgModel::whereRaw('FIND_IN_SET(?, customer_ids)', [$auth->id])->orderBy('id', 'desc')->get();

        if($msg){
            $return = $msg->map(function($item) {
                $res = [
                    'id' => $item->id,
                    'title' => $item->title,
                    'content' => $item->content,
                    'file' => $item->file,
                    'created_at' => $item->created_at->toDateTimeString(),
                ];
                return $res;
            })->toArray();
        }else{
            $return = [];
        }

        return $this->success($return);
    }

}
